package com.company.cloud.app.modules.config;

import com.company.cloud.common.constant.ConfigConstants;
import com.company.cloud.common.redis.service.RedisUtils;
import com.company.common.auth.intercepter.AuthorizationAnnotationInterceptor;
import com.company.common.auth.service.AnonyTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@ConditionalOnProperty(value = ConfigConstants.CONFIG_Auth_Interceptor_ENABLED, havingValue = "true")
@Slf4j
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private AnonyTokenService anonyTokenService;

    @Value("${saas.staff.log.url}")
    private String staffLogUrl;

    /**
     * Spring的拦截器配置
     * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 权限注解拦截器
        log.info("----------------WebMvcConfig : 权限注解拦截器-------------------------, staffLogUrl: {}", staffLogUrl);
        registry.addInterceptor(new AuthorizationAnnotationInterceptor(redisUtils,anonyTokenService, staffLogUrl));
        //registry.addInterceptor(new AuthorizationAnnotationInterceptor(redisUtils,anonyTokenService, "/"));
    }

}
